package com.muhuahealth;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author GSK
 * @version 1.0
 * @date 2022/10/18 20:56
 */
public class DeadLock {

    public static void main(String[] args) {
        List<Integer> list1 = Arrays.asList(1,2,3);
        List<Integer> list2 = Arrays.asList(4,5,6);
        new Thread(
                () -> {
                    synchronized (list1) {
                        for (int i : list1) {
                            System.out.println(i);
                        }
                        try {
                            Thread.sleep(1000);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                        synchronized (list2){
                            for (int i : list2) {
                                System.out.println(i);
                            }
                        }
                    }
                }
        ).start();

        new Thread(
                () -> {
                    synchronized (list2) {
                        for (int i : list2) {
                            System.out.println(i);
                        }
                        try {
                            Thread.sleep(1000);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                        synchronized (list1){
                            for (int i : list1) {
                                System.out.println(i);
                            }
                        }
                    }
                }
        ).start();
        int a = 'a';
        int b = 'b';
        int c = a + b;
        if(c > 180){
            a++;
        }else {
            b++;
        }
        System.out.println("a="+ a+",b="+b+",c="+c);

    }
}
